/*
 * @Author: szx
 * @Date: 2022-03-13 17:00:35
 * @LastEditTime: 2022-03-13 17:11:56
 * @Description:
 * @FilePath: \leetcode\other\银联-01. 回文链表.js
 */
function ListNode(val) {
    this.val = val;
    this.next = null;
}

/**
 * @param {ListNode} head
 * @return {boolean}
 */
var isPalindrome = function (head) {
    const vals = [];
    while (head !== null) {
        vals.push(head.val);
        head = head.next;
    }
    let flag = 0;
    for (let i = 0, j = vals.length - 1; i < j; ++i, --j) {
        if (vals[i] !== vals[j]) {
            if (flag == 0) {
                if (vals[i + 1] === vals[j]) {
                    flag = 1;
                    i++;
                    continue;
                }
                if (vals[i] === vals[j - 1]) {
                    flag = 1;
                    j--;
                    continue;
                }
                return false;
            }
            return false;
        }
    }
    return true;
};
